#include "config.h"

#ifdef DEVICE_PC_WATCHMEN_PCIE
#define DEV 4
#endif

#define DEV_ADDR 0U
#define CONFIG_SIZE 512U

void config_write_byte(unsigned int addr, unsigned char val) {
    EEPROM.write(addr, val);
    EEPROM.commit();
    
    delay(10UL);
}

unsigned char config_read_byte(unsigned int addr) {
    return EEPROM.read(addr);
}

void config_clear() {
    for (unsigned int i = 0; i < CONFIG_SIZE; i++) {
        EEPROM.write(i, 0xFF);
    }
    EEPROM.commit();
    delay(10UL);
}

void config_init() {
    EEPROM.begin(CONFIG_SIZE);
    if (config_read_byte(DEV_ADDR) != DEV) {
        config_clear();
        config_write_byte(DEV_ADDR, DEV);
    }
}